package com.hui.service;

import com.hui.entity.Course;
import com.hui.entity.CourseLesson;
import com.hui.entity.CourseSection;
import com.hui.mapper.CourseContentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 李昭辉
 * @Date: 2021/08/06/11:37
 * @Description:
 */
@Service("courseContentService")
public class CourseContentServiceImpl implements CourseContentService {
    @Autowired
    private CourseContentMapper courseContentMapper;

    @Override
    public List<CourseSection> getCourseSectionWithLesson(int courseId) {
        return courseContentMapper.getCourseSectionWithLesson(courseId);
    }

    @Override
    public Course getCourseByCourseId(Integer courseId) {
        return courseContentMapper.getCourseByCourseId(courseId);
    }

    @Override
    public void saveSection(CourseSection courseSection) {
        // 补全信息
        Date date = new Date();
        courseSection.setCreateTime(date);
        courseSection.setUpdateTime(date);
        courseSection.setStatus(1);//0:隐藏；1：待更新；2：已发布
        // 调用dao层，执行保存操作
        courseContentMapper.saveSection(courseSection);
    }

    @Override
    public void updateSection(CourseSection courseSection) {
        // 补全信息
        courseSection.setUpdateTime(new Date());
        // 调用dao层，执行修改操作
        courseContentMapper.updateSection(courseSection);
    }

    @Override
    public void updateSectionStatus(int id, int status) {
        // 封装及补全信息
        CourseSection section = new CourseSection();
        section.setId(id);
        section.setStatus(status);
        section.setUpdateTime(new Date());
        // 调用dao层，执行修改操作
        courseContentMapper.updateSectionStatus(section);
    }

    @Override
    public void saveLesson(CourseLesson courseLesson) {
        // 补全信息i
        Date date = new Date();
        courseLesson.setCreateTime(date);
        courseLesson.setUpdateTime(date);
        courseLesson.setStatus(1); //0:隐藏；1：待更新；2：已发布
        // 调用dao层，执行保存操作
        courseContentMapper.saveLesson(courseLesson);
    }
}
